package com.zjy.business.common.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.zjy.business.common.service.FileService;
import com.zjy.web.domain.model.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 通用-文件上传
 */
@RestController
@RequestMapping("/common/file")
@Validated
@RequiredArgsConstructor
public class FileController {

    private final FileService fileService;

    /**
     * 上传文件
     *
     * @param file 文件
     */
    @PostMapping(value = "/uploadFile", consumes = "multipart/*", headers = "content-type=multipart/form-data")
    public Result<String> uploadFile(MultipartFile file) {
        return Result.SUCCESS(fileService.uploadFile(file));
    }


    /**
     * 获取文件前缀
     */
    @SaIgnore
    @GetMapping(value = "/getFilePrefix")
    public Result<String> getFilePrefix() {
        return Result.SUCCESS(fileService.getFilePrefix());
    }

}
